package cn.bob.org.controller;

import cn.bob.basic.utils.AjaxResult;
import cn.bob.org.domain.User;
import cn.bob.org.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author bob
 * @data 2022/10/4-15:28
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private UserService service;

    @PostMapping
    public AjaxResult login(@RequestBody User user, HttpSession session){
        try {
            User userLogin = service.findUserLogin(user);
            session.setAttribute("USER",userLogin);
            if (userLogin!=null){
                return AjaxResult.me().success();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return AjaxResult.me().fail("账号未启用或密码错误！！");
    }

}
